import random

def guess_number():
    target_number=random.randint(1,100)
    print("我已经想好一个数字了")
    while True:
        try:
           user_number=int(input("请输入一个数字:"))
           if user_number > target_number:
               print("数值过大了，重新输入")
           elif user_number < target_number:
               print("数字过小了，重新输入")
           else :
               print("恭喜你猜对了")
        except ValueError:
            print("输入无效，重新输入")

guess_number()
